<template>
	<view>

		<view class="cu-custom" :style="[{height:CustomBar + 'px'}]">
			<view class="cu-bar fixed" :style="style" :class="[bgImage!=''?'none-bg text-white bg-img':'',top/moveMax>=1?bgColorFixed:bgColor]">
				<view class="action" @tap="BackPage" v-if="isBack">
					<text class="cuIcon-back"></text>
					<slot name="left"></slot>
				</view>
				<view v-else>
					<slot name="left"></slot>
				</view>
				<view class="content" :style="[{top:StatusBar + 'px'}]">
					<slot name="content"></slot>
				</view>
				<slot name="right"></slot>
			</view>
		</view>

		<view class="cu-custom pos-a" style="z-index: 10;" :style="[{height:CustomBar + 'px'},{opacity:top/moveMax>=1?1:top/moveMax}]">
			<view class="cu-bar fixed" :style="style" :class="[bgImage!=''?'none-bg text-white bg-img':'',bgColorFixed]">
				<view class="action" @tap="BackPage" v-if="isBack">
					<text class="cuIcon-back"></text>
					<!-- <slot name="left"></slot> -->
				</view>
				<view v-else>
					<!-- <slot name="left"></slot> -->
				</view>
				<view class="content" :style="[{top:StatusBar + 'px'}]">
					<slot name="content"></slot>
				</view>
				<!-- <slot name="right"></slot> -->
			</view>
		</view>

	</view>
</template>

<script>
	export default {
		data() {
			return {
				StatusBar: this.StatusBar,
				CustomBar: this.CustomBar,
				changeStatus: false,
				moveMax: 50, //最大移动距离
				curColor:''
			};
		},
		name: 'stop',
		computed: {
			style() {
				var StatusBar = this.StatusBar;
				var CustomBar = this.CustomBar;
				var bgImage = this.bgImage;
				var style = `height:${CustomBar}px;padding-top:${StatusBar}px;`;
				if (this.bgImage) {
					style = `${style}background-image:url(${bgImage});`;
				}
				return style
			}
		},
		props: {
			bgColor: {
				type: String,
				default: 'bg-gradual-green'
			},
			bgColorFixed: {
				type: String,
				default: 'bg-white'
				// default: 'bg-gradual-blue'
			},
			isBack: {
				type: [Boolean, String],
				default: false
			},
			bgImage: {
				type: String,
				default: ''
			},
			top: {
				type: Number,
				default: 0
			},
			startColor: {
				type: String,
				default: 'white'
			},
			changed: {
				type: Number,
				default: 0
			},
			
		},
		methods: {
			BackPage() {
				uni.navigateBack({
					delta: 1
				});
			},
			updateStatusBarColor(val){
				// this.log(val)
				if (val / this.moveMax >= 1) {
					//状态二，改为changeStatus = true
					if (this.changeStatus == false) {
						this.changeStatus = true
						if (this.startColor == 'white') {
							this.curColor = ''
							uni.setNavigationBarColor({
								"frontColor": '#000000',
								"backgroundColor": '#eaeaea',
								"animation": {
									duration: 200,
									timingFunc: 'easeIn'
								}
							})
						} else {
							this.curColor = 'white'
							uni.setNavigationBarColor({
								"frontColor": '#ffffff',
								"backgroundColor": '#1f1f1f',
								"animation": {
									duration: 200,
									timingFunc: 'easeIn'
								}
							})
						}
					}
				} else {
					//状态一，改为changeStatus = false
					if (this.changeStatus == true) {
						this.changeStatus = false
						if (this.startColor == 'white') {
							this.curColor = 'white'
							uni.setNavigationBarColor({
								"frontColor": '#ffffff',
								"backgroundColor": '#eaeaea',
								"animation": {
									duration: 200,
									timingFunc: 'easeIn'
								},fail(e) {
									this.log(e)
								}
							})
						} else {
							this.curColor = ''
							uni.setNavigationBarColor({
								"frontColor": '#000000',
								"backgroundColor": '#eaeaea',
								"animation": {
									duration: 200,
									timingFunc: 'easeIn'
								}
							})
						}
					}
				}
				
			}
		},
		watch: {
			top(val) {
				this.updateStatusBarColor(val)
			},
			changed(val){
				this.log(val)
				this.log(this.changeStatus)
				this.log(this.curColor)
				this.log(this.startColor)
				let isMoveOut = (this.top / this.moveMax >= 1)
				if (isMoveOut != true) {
					this.changeStatus = false
					if (this.startColor == 'white') {
						this.curColor = 'white'
						uni.setNavigationBarColor({
							"frontColor": '#ffffff',
							"backgroundColor": '#1f1f1f',
							"animation": {
								duration: 200,
								timingFunc: 'easeIn'
							},fail(e) {
								this.log(e)
							}
						})
					} else {
						this.curColor = ''
						uni.setNavigationBarColor({
							"frontColor": '#000000',
							"backgroundColor": '#eaeaea',
							"animation": {
								duration: 200,
								timingFunc: 'easeIn'
							}
						})
					}
				}else{
					this.changeStatus = true
					if (this.startColor != 'white') {
						this.curColor = 'white'
						this.log('change fff')
						uni.setNavigationBarColor({
							"frontColor": '#ffffff',
							"backgroundColor": '#1f1f1f',
							"animation": {
								duration: 200,
								timingFunc: 'easeIn'
							},fail(e) {
								this.log(e)
							}
						})
					} else {
						this.curColor = ''
						uni.setNavigationBarColor({
							"frontColor": '#000000',
							"backgroundColor": '#eaeaea',
							"animation": {
								duration: 200,
								timingFunc: 'easeIn'
							}
						})
					}
				}
			}
		}
	}
</script>

<style>

</style>
